<?php
class MemcacheQueue {
	private $cfg;
	private $mem;
	
	public function __construct($cfg) {
		$this->cfg = $cfg;
		$this->setMem();
	}
	
	public function set($val) {
		memcache_set($this->mem, $this->cfg['key'], $val);
	}
	
	public function get() {
		return memcache_get($this->mem, $this->cfg['key']);
	}
	
	private function setMem() {
		$memcaches = $this->cfg['memcaches'];
		# the first memcache server is primary
		$primary = array_shift($memcaches);
		$this->mem = memcache_connect($primary[0], $primary[1]);
		# add secondary memcache servers
		while($secondary = array_shift($memcaches)) {
			memcache_add_server($this->mem, $secondary[0], $secondary[1]);
		}
	}
}
?>